package GraphProperties;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import Global.ConstantVariable;
import Global.DirectoryStructureAndSettingsClass;
import Global.GlobalClass;
import SyntheticData.syntheticDataGeneratorClass;
import SyntheticData.syntheticDataGeneratorClass.TogetherFilesHolderClass;
import Utility.ListsPerGivenLevelsHolderClass;
import Utility.WorkerUtilityClass;

public class HomophilyRelatedPropsClass extends GenericGraphPropertyClass implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8222639477822024008L;
	double[] homophilyListOfTheNodes;
	double homophilyOfTheGraph;
	
	double[] homophilyDistrubutionVsDegreeLevels;
	double[] homophilyDistrubutionErrorBarsVsDegreeLevels;
	
	double[] homophilyDistrubutionVsCCLevels;
	double[] homophilyDistrubutionErrorBarsVsCCLevels;
	
	double[] homophilyLevels;
	double[] homophilyFrequencyForTheLevels;
	
	double[] precisionIntervalsForHomophilyDiscritization;	//asil bu.
	int lengthOfTheHomophilyIntervals;
	
	HomophilyRelatedPropsClass(PropertiesOfGraphClass propertiesIBelongTo)
	{	
		super(propertiesIBelongTo);
		homophilyOfTheGraph = 0;		
	}
	
	public void setHomophilyRelatedParameters(double[] homophilyListOfTheNodes, double homophilyOfTheGraph)
	{
		this.homophilyListOfTheNodes = homophilyListOfTheNodes;			
		this.homophilyOfTheGraph = homophilyOfTheGraph;
		
		lengthOfTheHomophilyIntervals = (int) Math.ceil(1.0/ConstantVariable.HomophilyRelated_ConstantVariables.PRECISION_LEVEL_FOR_HOMOPHILY_DISCRETIZATON)+1;
		precisionIntervalsForHomophilyDiscritization =  new double[lengthOfTheHomophilyIntervals];
		
		calculatehomophilyVsDegreeDistribution();		
		analyzeHomophilyDistributionOfTheGraph();
		//homophilyCalculationIsCompleted();
	}
	
	public void setHomophilyvsCCRelatedParameters(double[] homophilyDistrubutionVsCCLevels, double[] homophilyDistrubutionErrorBarsVsCCLevels)
	{
		this.homophilyDistrubutionVsCCLevels = homophilyDistrubutionVsCCLevels;			
		this.homophilyDistrubutionErrorBarsVsCCLevels = homophilyDistrubutionErrorBarsVsCCLevels;
		homophilyCalculationIsCompleted();
	}
		
	public double[] getHomophilyListOfTheNodes()
	{
		return homophilyListOfTheNodes;
	}
	
	public double getHomophilyOfTheGraph()
	{
		return homophilyOfTheGraph;
	}
	
	void analyzeHomophilyDistributionOfTheGraph()
	{
		double minHomophily = Double.MAX_VALUE;
		double maxHomophily = -1;
		
		
		for(int i=0; i<homophilyListOfTheNodes.length; i++)
		{
			if(homophilyListOfTheNodes[i] > maxHomophily)
				maxHomophily = homophilyListOfTheNodes[i];
			
			if(homophilyListOfTheNodes[i] < minHomophily)
				minHomophily = homophilyListOfTheNodes[i];
			
			precisionIntervalsForHomophilyDiscritization[(int) Math.floor(homophilyListOfTheNodes[i]*(1.0/ConstantVariable.HomophilyRelated_ConstantVariables.PRECISION_LEVEL_FOR_HOMOPHILY_DISCRETIZATON))]++;
		}
		
		System.out.println("maxClusteringCoefficient:"+maxHomophily);
		System.out.println("minClusteringCoefficient:"+minHomophily);
		System.out.println("clusteringCoefficientOfTheGraph:"+homophilyOfTheGraph);
		
		int sifirOlmayanHomophilySayisi=0;
		ArrayList<Double> homophilyLevelsList = new ArrayList<Double>();
		
		
		for(int i=0; i<precisionIntervalsForHomophilyDiscritization.length; i++)
		{
			if(precisionIntervalsForHomophilyDiscritization[i]!=0)
			{
				System.out.println(i+":"+precisionIntervalsForHomophilyDiscritization[i]);
				sifirOlmayanHomophilySayisi++;
				homophilyLevelsList.add((WorkerUtilityClass.roundToDecimals((double)i*ConstantVariable.HomophilyRelated_ConstantVariables.PRECISION_LEVEL_FOR_HOMOPHILY_DISCRETIZATON, 2)));
			}
		}
		
		System.out.println("sifirOlmayanHomophilySayisi:"+sifirOlmayanHomophilySayisi);
		
		homophilyLevels = WorkerUtilityClass.getDoubleArrayFromDoubleArrayList(homophilyLevelsList);
		
		WorkerUtilityClass.printArray(homophilyLevels, "homophilyLevels");
		
		double homophilyOfTheElement;
		Map<Double, Integer> homophilyDistibutionMap = new HashMap<Double, Integer>(); 
		
		for(int i=0; i<precisionIntervalsForHomophilyDiscritization.length; i++)
		{
			if(precisionIntervalsForHomophilyDiscritization[i]>0)
			{
				homophilyOfTheElement = (double)i*ConstantVariable.ClusteringCoefficentRelated_ConstantVariables.PRECISION_LEVEL_FOR_CC_DISCRETIZATON;
				
				double size = homophilyOfTheElement; 
				Integer n = homophilyDistibutionMap.get(size); 
				if (n == null) { 
					homophilyDistibutionMap.put(size, 1); 
				} else { 
					homophilyDistibutionMap.put(size, n + 1); 
				}								
			}		
		}			

		System.out.println(homophilyDistibutionMap);
		
		System.out.println("Sorted Homophily hashmap START");
		
		System.out.println(Utility.WorkerUtilityClass.sortHashMapByValuesD((HashMap) homophilyDistibutionMap));
		
		System.out.println("Sorted Homophily hashmap END");	
	}

	
	void calculatehomophilyVsDegreeDistribution()
	 { 
		 double[] degreeLevels=propertiesIBelongTo.degreeDistributionRelatedProps.degreeLevels;
		 int numberOfDegreeLevels = degreeLevels.length;

		 double[] degreeListOfTheNodes = propertiesIBelongTo.degreeDistributionRelatedProps.degreeListOfNodes;	    	

		 HashMap<Double, Integer> degreeDistibutionMapIndex = new HashMap<Double, Integer>();

		 for(int i=0; i<numberOfDegreeLevels; i++)
			 degreeDistibutionMapIndex.put(degreeLevels[i], i);

		 int indexOfTheDegreeDistList;
		 
		 ListsPerGivenLevelsHolderClass[] homophilyLists = ListsPerGivenLevelsHolderClass.getNewLevelSeperatedList(numberOfDegreeLevels);
		 
		 for(int i=0; i<degreeListOfTheNodes.length; i++)
		 {
			 if(degreeListOfTheNodes[i]!=0)
			 {
				 indexOfTheDegreeDistList = degreeDistibutionMapIndex.get(WorkerUtilityClass.convertToSomeScale(degreeListOfTheNodes[i]));
				 homophilyLists[indexOfTheDegreeDistList].add(homophilyListOfTheNodes[i]);				 
			 }
		 }
		 
		 homophilyDistrubutionVsDegreeLevels = new double[numberOfDegreeLevels];
		 homophilyDistrubutionErrorBarsVsDegreeLevels = new double[numberOfDegreeLevels];
		 
		 double[] doubleArrayFormOfTheList; 
		 
		 for(int i=0; i<homophilyLists.length; i++)
		 {
			 doubleArrayFormOfTheList = WorkerUtilityClass.getDoubleArrayFromDoubleArrayList(homophilyLists[i].getArrayListOfTheDoubleValues());
			 homophilyDistrubutionVsDegreeLevels[i]=WorkerUtilityClass.getAverage(doubleArrayFormOfTheList);
			 homophilyDistrubutionErrorBarsVsDegreeLevels[i]=WorkerUtilityClass.findErrorBar(doubleArrayFormOfTheList);
			 System.out.println("i:"+i+":"+homophilyLists[i].size() +":"+homophilyDistrubutionErrorBarsVsDegreeLevels[i]);
		 }
	 }
	
	void homophilyCalculationIsCompleted()
	{
		String datasetName = DirectoryStructureAndSettingsClass.getDatasetName();
		
		try {
			
			/**************************PURE HOMOPHILY LIST*********************************/
			
			outForPureRawFile = createRawPureHomophilyResultsFile(datasetName);
			Utility.FileUtilityClass.writeArrayToFile(outForPureRawFile, homophilyListOfTheNodes, ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForHomophilyOfNodes, "Homophily of Nodes for " + datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType);
			outForPureRawFile.close();
			
			/**************************HOMOPHILY DISTRIBUTION LIST*********************************/
			
			outForRawFile = createRawHomophilyResultsFile(datasetName);
			Utility.FileUtilityClass.writeTwoArraysToFile(outForRawFile, propertiesIBelongTo.degreeDistributionRelatedProps.degreeLevels, homophilyDistrubutionVsDegreeLevels, ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForDegreesDistributionLevelsOfNodes, ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForHomophilyDistributionOfNodes, "Homophily Of The Graph for " + datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType);
			outForRawFile.close();
			
			/************************** HOMOPHILY VS DEGREE BAR PLOTS*********************************/
			
			String drawingSetting = null;
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE)
				drawingSetting = ConstantVariable.Matlab_ConstantVariables.DrawingSettings.HomophilyRelatedDrawingSettings.DRAWING_SETTING_FOR_HOMOPHILY_DISTRIBUTION_VS_DEGREE_FIGURE_FOR_LINK_GRAPH;
			else if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
				drawingSetting = ConstantVariable.Matlab_ConstantVariables.DrawingSettings.HomophilyRelatedDrawingSettings.DRAWING_SETTING_FOR_HOMOPHILY_DISTRIBUTION_VS_DEGREE_FIGURE_FOR_CONTENT_GRAPH;
			
			outForMatlabCodeFile = createMatlabCodeHomophilyDistributionResultsFile(datasetName);
			createHomophilyDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.ERRORBAR_LINEAR_SCALE, false, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.DONT_CARE, drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);		
			outForMatlabCodeFile.close();
			
			outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.ERRORBAR_LINEAR_SCALE);
			prepareTexFileForTheCreatedMatlabFigure();			
			outForTexForMatlabFigureFile.close();
			
			copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.HOMOPHILY_VS_DD_MATLAB_FIGURES_TEX_ALL_IN_ONE_FILENAME, false);
			
			/************************** HOMOPHILY VS DEGREE BAR TOGETHER PLOTS FOR SYNTHETIC*********************************/
			
			//TODO AS EKLEME YAPIYOR..AYNI PARAMETRELI DATASET PLOTLARINI AYNI GRAFTA YAPMA!!!
			if(GlobalClass.RunningValues.executionFor==ConstantVariable.DataSet_Constants.SYNTETIC_DATASET)
			{	
				TogetherFilesHolderClass currentTogetherFileHolder;
				currentTogetherFileHolder = syntheticDataGeneratorClass.getOutForMatlabCodeHomophilyVsDDPDFResultsTogetherFile();
				String nameBackup = new String(matlabFileName);			
				matlabFileName = currentTogetherFileHolder.matlabFileName;
				outForMatlabCodeFile = currentTogetherFileHolder.out;				 
				createHomophilyDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.DefaultScaleTypes.DEFAULT_SCALE_TYPE_TO_BE_USED_WITH_SYNTHETIC_TOGETHER_PLOTS, true, syntheticDataGeneratorClass.getGraphOrderForTogetherGraphicResults(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE, false), drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, false);
				matlabFileName = nameBackup;
			}
			
			/**************************HOMOPHILY VS DEGREE DOT PLOTS**************/
			
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE)
				drawingSetting = ConstantVariable.Matlab_ConstantVariables.DrawingSettings.HomophilyRelatedDrawingSettings.DRAWING_SETTING_FOR_DOT_HOMOPHILY_DISTRIBUTION_VS_DEGREE_FIGURE_FOR_LINK_GRAPH;
			else if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
				drawingSetting = ConstantVariable.Matlab_ConstantVariables.DrawingSettings.HomophilyRelatedDrawingSettings.DRAWING_SETTING_FOR_DOT_HOMOPHILY_DISTRIBUTION_VS_DEGREE_FIGURE_FOR_CONTENT_GRAPH;
			
			outForMatlabCodeFile = createMatlabCodeDotHomophilyDistributionResultsFile(datasetName, false);
			createDotHomophilyVsDegreePlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE, false, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.DONT_CARE, drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);
			outForMatlabCodeFile.close();
			
			outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE);
			prepareTexFileForTheCreatedMatlabFigure();			
			outForTexForMatlabFigureFile.close();
			
			copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.HOMOPHILY_VS_DD_MATLAB_FIGURES_TEX_ALL_IN_ONE_FILENAME, false);
			
			/************************** HOMOPHILY VS DEGREE DOT TOGETHER PLOTS FOR SYNTHETIC*********************************/
			
			//TODO AS EKLEME YAPIYOR..AYNI PARAMETRELI DATASET PLOTLARINI AYNI GRAFTA YAPMA!!!
			if(GlobalClass.RunningValues.executionFor==ConstantVariable.DataSet_Constants.SYNTETIC_DATASET)
			{
				TogetherFilesHolderClass currentTogetherFileHolder;
				currentTogetherFileHolder = syntheticDataGeneratorClass.getOutForMatlabCodeHomophilyVsDDDotPDFResultsTogetherFile();
				String nameBackup = new String(matlabFileName);			
				matlabFileName = currentTogetherFileHolder.matlabFileName;
				outForMatlabCodeFile = currentTogetherFileHolder.out;				 
				createDotHomophilyVsDegreePlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE, true, syntheticDataGeneratorClass.getGraphOrderForTogetherGraphicResults(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE, false), drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, false);
				matlabFileName = nameBackup;
			}
			
			/**************************HOMOPHILY VS DEGREE BAR PLOTS COMBO*********************************/
			
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE)
			{
				outForMatlabCodeFile = createMatlabCodeHomophilyDistributionComboResultsFile(datasetName, false);
				createHomophilyDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.ERRORBAR_LINEAR_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.FIRST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.HomophilyRelatedDrawingSettings.DRAWING_SETTING_FOR_HOMOPHILY_DISTRIBUTION_VS_DEGREE_COMBO_FIGURE_FOR_LINK_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);			
			}
			else if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForMatlabCodeFile = createMatlabCodeHomophilyDistributionComboResultsFile(datasetName, true);
				createHomophilyDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.ERRORBAR_LINEAR_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.LAST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.HomophilyRelatedDrawingSettings.DRAWING_SETTING_FOR_HOMOPHILY_DISTRIBUTION_VS_DEGREE_COMBO_FIGURE_FOR_CONTENT_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);
			}
				
			outForMatlabCodeFile.close();

			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.ERRORBAR_LINEAR_SCALE);
				prepareTexFileForTheCreatedMatlabFigure();			
				outForTexForMatlabFigureFile.close();
				
				copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.HOMOPHILY_VS_DD_MATLAB_FIGURES_TEX_COMBO_IN_ONE_FILENAME, true);
			}
			
			/**************************HOMOPHILY VS DEGREE DOT PLOTS COMBO**************/
			
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE)
			{
				outForMatlabCodeFile = createMatlabCodeDotHomophilyDistributionComboResultsFile(datasetName, false);
				createDotHomophilyVsDegreePlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.FIRST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.HomophilyRelatedDrawingSettings.DRAWING_SETTING_FOR_DOT_HOMOPHILY_DISTRIBUTION_VS_DEGREE_COMBO_FIGURE_FOR_LINK_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);
			}		
			else if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForMatlabCodeFile = createMatlabCodeDotHomophilyDistributionComboResultsFile(datasetName, true);
				createDotHomophilyVsDegreePlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.LAST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.HomophilyRelatedDrawingSettings.DRAWING_SETTING_FOR_DOT_HOMOPHILY_DISTRIBUTION_VS_DEGREE_COMBO_FIGURE_FOR_CONTENT_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);				
			}
			outForMatlabCodeFile.close();
			
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE);
				prepareTexFileForTheCreatedMatlabFigure();			
				outForTexForMatlabFigureFile.close();
				
				copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.HOMOPHILY_VS_DD_MATLAB_FIGURES_TEX_COMBO_IN_ONE_FILENAME, true);
			}
		} catch (IOException e) {			
			e.printStackTrace();
		}		
	}
	
    public BufferedWriter createRawPureHomophilyResultsFile(String datasetName)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.HOMOPHILY_RELATED_DATA_FOLDER_NAME    				
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.RAW_DATA_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"HomophilysOfNodes.txt"; 
    	
    	return DirectoryStructureAndSettingsClass.createTheFileSpecified(path, fileName, false);
    }
    
    /**********************************************/
	
    public BufferedWriter createRawHomophilyResultsFile(String datasetName)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.HOMOPHILY_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.RAW_DATA_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"HomophilyVsDegreeDistribution.txt";
    	
    	
    	return DirectoryStructureAndSettingsClass.createTheFileSpecified(path, fileName, false);
    }
    
    /**********************************************/

    public BufferedWriter createMatlabCodeHomophilyDistributionResultsFile(String datasetName)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.HOMOPHILY_RELATED_DATA_FOLDER_NAME;
    				
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"HomophilyDistribution";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	return DirectoryStructureAndSettingsClass.createTheFileSpecified(path, fileName, false);
    }
    
    /**********************************************/
    
    public BufferedWriter createMatlabCodeDotHomophilyDistributionResultsFile(String datasetName, boolean appendMode)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.HOMOPHILY_RELATED_DATA_FOLDER_NAME;
    				
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"HomophilyDotDistribution";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	return DirectoryStructureAndSettingsClass.createTheFileSpecified(path, fileName, appendMode);
    }   

    
    /**********************************************/

    public BufferedWriter createMatlabCodeHomophilyDistributionComboResultsFile(String datasetName, boolean appendMode)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.HOMOPHILY_RELATED_DATA_FOLDER_NAME;
    				    				    	
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"HomophilyCombo";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	return DirectoryStructureAndSettingsClass.createTheFileSpecified(path, fileName, appendMode);
    }
    
    /**********************************************/
        
    public BufferedWriter createMatlabCodeDotHomophilyDistributionComboResultsFile(String datasetName, boolean appendMode)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.HOMOPHILY_RELATED_DATA_FOLDER_NAME;
    				    				    	
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"HomophilyDotCombo";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	return DirectoryStructureAndSettingsClass.createTheFileSpecified(path, fileName, appendMode);
    }
    
        
    /**********************************************/
    
    void createHomophilyDistributionPlotCodeForMatlab(BufferedWriter outForMatlabCodeFile, int type, boolean isForCombo, int order, String drawingSettings, int distributionPlotType, boolean generateFigure)
    {
    	double[] degreeLevels = propertiesIBelongTo.degreeDistributionRelatedProps.degreeLevels;
    	createPlotCodeForMatlab(outForMatlabCodeFile, type, isForCombo, order, degreeLevels, homophilyDistrubutionVsDegreeLevels, homophilyDistrubutionErrorBarsVsDegreeLevels, "Homophily vs Degree Distribution", "Degree (D)", "Homophily (H)", drawingSettings, distributionPlotType, generateFigure);
    }
    
    void createDotHomophilyVsDegreePlotCodeForMatlab(BufferedWriter outForMatlabCodeFile, int type, boolean isForCombo, int order, String drawingSettings, int distributionPlotType, boolean generateFigure)
    {    	
    	double[] degreeList = propertiesIBelongTo.prepareForCorrelationCalculation(propertiesIBelongTo.degreeDistributionRelatedProps.degreeListOfNodes, 1);
    	double[] cleanedHomophilyListOfTheNodes = propertiesIBelongTo.prepareForCorrelationCalculation(homophilyListOfTheNodes, 1);
    	createPlotCodeForMatlab(outForMatlabCodeFile, type, isForCombo, order, degreeList, cleanedHomophilyListOfTheNodes, null, "Homophily vs Degree", "Degree (D)", "Homophily (H)", drawingSettings, distributionPlotType, generateFigure);
    }
}
